using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisGotoStatement : AnalysisStatement
{
    internal AnalysisGotoStatement(GotoStatement syntaxNode,
        AnalysisIdentifier? nameIdentifier,
        AnalysisNode? parent) :
        base(AnalysisBoundKinds.GotoStatement, syntaxNode, parent)
    {
        Syntax = syntaxNode;
        NameIdentifier = nameIdentifier;

        if (NameIdentifier != null)
        {
            NameIdentifier.Parent = this;
        }
    }


    public override GotoStatement Syntax { get; }

    public AnalysisIdentifier? NameIdentifier { get; }

    public override int ChildrenCount => NameIdentifier == null ? 0 : 1;

    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return NameIdentifier == null ? [] : [NameIdentifier];
    }


    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("AnalysisGotoStatement is read-only.");
    }
}

public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个Goto语句
    /// </summary>
    /// <param name="syntaxNode">原始语法节点</param>
    /// <param name="nameIdentifier">行标签名称</param>
    /// <param name="parent">父节点，可以忽略</param>
    /// <param name="withSymbol">语法节点所在的With语句上下文类型符号</param>
    public static AnalysisGotoStatement GotoStatement(GotoStatement syntaxNode,
        AnalysisIdentifier? nameIdentifier,
        AnalysisNode? parent,
        ITypeSymbol? withSymbol)
    {
        return new AnalysisGotoStatement(syntaxNode, nameIdentifier, parent).WithContainingWithSymbol(withSymbol);
    }
}